local roulin = fk.CreateSkill {

  name = "joy__roulin",

  tags = { Skill.Compulsory, },

}



roulin:addEffect(fk.TargetSpecified, {
  name = "joy__roulin",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified, fk.TargetConfirmed,fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(roulin.name) and data.card.trueName == "slash" then
      if event == fk.TargetSpecified then
        return player:getMark("@@joy__roulin-turn") > 0 or player.room:getPlayerById(data.to).gender == General.Female
      elseif event ==  fk.TargetConfirmed then
        return player:getMark("@@joy__roulin-turn") > 0 or player.room:getPlayerById(data.from).gender == General.Female
      end
    elseif player:hasSkill(roulin.name) and data.card.trueName == "slash" then
      return not data.damageDealt and data.extra_data and data.extra_data.joy__roulin
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      local room = player.room
      local ids = room:getCardsFromPileByRule(".|.|club,spade", 1, "DrawPile")
      if #ids > 0 then
        room:obtainCard(player, ids[1], false, fk.ReasonPrey)
      end
    else
      data.extra_data = data.extra_data or {}
      data.extra_data.joy__roulin = true
      data.fixedResponseTimes = data.fixedResponseTimes or {}
      data.fixedResponseTimes["jink"] = 2
    end
  end,
})
roulin:addEffect(fk.TargetConfirmed, {
  name = "joy__roulin",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified, fk.TargetConfirmed,fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(roulin.name) and data.card.trueName == "slash" then
      if event == fk.TargetSpecified then
        return player:getMark("@@joy__roulin-turn") > 0 or player.room:getPlayerById(data.to).gender == General.Female
      elseif event ==  fk.TargetConfirmed then
        return player:getMark("@@joy__roulin-turn") > 0 or player.room:getPlayerById(data.from).gender == General.Female
      end
    elseif player:hasSkill(roulin.name) and data.card.trueName == "slash" then
      return not data.damageDealt and data.extra_data and data.extra_data.joy__roulin
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      local room = player.room
      local ids = room:getCardsFromPileByRule(".|.|club,spade", 1, "DrawPile")
      if #ids > 0 then
        room:obtainCard(player, ids[1], false, fk.ReasonPrey)
      end
    else
      data.extra_data = data.extra_data or {}
      data.extra_data.joy__roulin = true
      data.fixedResponseTimes = data.fixedResponseTimes or {}
      data.fixedResponseTimes["jink"] = 2
    end
  end,
})
roulin:addEffect(fk.CardUseFinished, {
  name = "joy__roulin",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.TargetSpecified, fk.TargetConfirmed,fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(roulin.name) and data.card.trueName == "slash" then
      if event == fk.TargetSpecified then
        return player:getMark("@@joy__roulin-turn") > 0 or player.room:getPlayerById(data.to).gender == General.Female
      elseif event ==  fk.TargetConfirmed then
        return player:getMark("@@joy__roulin-turn") > 0 or player.room:getPlayerById(data.from).gender == General.Female
      end
    elseif player:hasSkill(roulin.name) and data.card.trueName == "slash" then
      return not data.damageDealt and data.extra_data and data.extra_data.joy__roulin
    end
  end,
  on_use = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      local room = player.room
      local ids = room:getCardsFromPileByRule(".|.|club,spade", 1, "DrawPile")
      if #ids > 0 then
        room:obtainCard(player, ids[1], false, fk.ReasonPrey)
      end
    else
      data.extra_data = data.extra_data or {}
      data.extra_data.joy__roulin = true
      data.fixedResponseTimes = data.fixedResponseTimes or {}
      data.fixedResponseTimes["jink"] = 2
    end
  end,
})

return roulin